<?php
/**
 * Created by PhpStorm.
 * User: 静静
 * Date: 2018/12/25
 * Time: 11:45
 */

namespace App\Model;


trait Common
{

  /**
   * 将数据转换为layui表格格式数据
   * @param $list
   * @return \Illuminate\Http\JsonResponse
   */
  public static function returnLayUiData($list)
  {
    $data = [
        'code' => 0,
        'msg' => '',
        'count' => $list['total'],
        'data' => $list['data']
    ];
    return response()->json($data);
  }

  /**
   * 获取条数 默认为20条
   * @param \Request $request
   * @return int|mixed
   */
  public static function getLimit($limit = null)
  {
    return empty($limit) ? 20 : $limit;
  }

  /**
   * 设置显示和不显示的样式
   * @param $is_show
   * @return string
   */
  public static function getIsStatus($is_status)
  {
    switch ($is_status) {
      case 0:
        $str = '<span class="layui-badge layui-bg-gray">审核中</span>';
        break;
      case 1:
        $str = '<span class="layui-badge layui-bg-green">审核通过</span>';
        break;
      default:
        $str = '<span class="layui-badge layui-bg-green">审核拒绝</span>';
        break;
    }
    return $str;
  }

  /**
   * 获取物料状态
   * @param $type
   * @return string
   */
  static function getMaterielType($type)
  {
    switch ($type) {
      case 0:
        $str = '<span class="layui-badge layui-bg-gray">测试户</span>';
        break;
      default:
        $str = '<span class="layui-badge layui-bg-green">正式户</span>';
        break;
    }
    return $str;
  }

}